﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZX.Web.UI.Controls;
using ZX.CRM.Library;
using ZX.CRM.Bussiness;
using ZX.Web.UI.Controls.ControlBind;
using ZX.BLL;
using ZX.SYS.Library;

namespace ZX.WebApp.Crm.Customer
{
    public partial class ModifyCustomerOld : EditUIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BTCrmCustomer bll = new BTCrmCustomer();
            BDatPhraseDetail bllDetail = new BDatPhraseDetail();

            //省份
            IList<SysProvince> ListProvinceData = bll.GetAllProvince();
            DropDownListControl.DropDataSourceBind(this.Province, ListProvinceData, "Name", "Code");
            //虚拟部门
            //IList<V_CrmUserArea> ListDept = bll.GetVirtualDepartmentNew(this.UserId);
            //DropDownListControl.DropDataSourceBind(this.AreaId, ListDept, "DeptName", "DeptID");
            //客户规模(员工人数)
            IList<DatPhraseDetail> ListDetailNumber = bllDetail.GetDatPhraseDetailByClassValue("CustomerScope");
            DropDownListControl.DropDataSourceBind(this.PersonId, ListDetailNumber, "PhraseText", "PhraseID");
            //行业
            //IList<DatPhraseDetail> ListDetailTrade = bllDetail.GetDatPhraseDetailByClassValue("Trade");
            //DropDownListControl.DropDataSourceBind(this.TradeId, ListDetailTrade, "PhraseText", "PhraseID");
            //产值
            IList<DatPhraseDetail> ListDetailProduct = bllDetail.GetDatPhraseDetailByClassValue("Product");
            DropDownListControl.DropDataSourceBind(this.ProductId, ListDetailProduct, "PhraseText", "PhraseID");
            //公司性质
            IList<DatPhraseDetail> ListDetailProperty = bllDetail.GetDatPhraseDetailByClassValue("Property");
            DropDownListControl.DropDataSourceBind(this.PropertyId, ListDetailProperty, "PhraseText", "PhraseID");

            if (this.GetStringFromQueryString("flag", "") == "0") //新增
            {

            }
            else   //修改
            {
                string strId = this.GetStringFromQueryString("id", "");
                this.ID.Value = strId;
                CrmCustomerOld customer = bll.GetCrmCustomerOldData(new Guid(strId));
                if (customer != null)
                {
                    this.CustomerName.Value = customer.CustomerName;

                    IList<V_SysProvince> ListProvince = bll.GetProvinceInfo(customer.Province);
                    if (ListProvince != null && ListProvince.Count > 0)
                    {
                        this.Province.SelectedIndex = this.Province.Items.IndexOf(this.Province.Items.FindByText(ListProvince[0].Province));
                    }
                    IList<V_SysProvince> ListCity = bll.GetProvinceInfo(customer.Province, customer.City);
                    if (ListCity != null && ListCity.Count > 0)
                    {
                        //绑定城市
                        IList<SysCity> city = bll.GetAllCityByProviceName(customer.Province);
                        DropDownListControl.DropDataSourceBind(this.City, city, "Name", "Code");
                        this.City.SelectedIndex = this.City.Items.IndexOf(this.City.Items.FindByText(ListCity[0].City));
                    }
                    IList<V_SysProvince> ListArea = bll.GetProvinceInfo(customer.Province, customer.City);
                    if (ListArea != null && ListArea.Count > 0)
                    {
                        //绑定区县
                        this.Area.DataSource = ListArea;
                        this.Area.DataTextField = "Area";
                        this.Area.DataValueField = "AreaCode";
                        this.Area.DataBind();
                        this.Area.SelectedIndex = this.Area.Items.IndexOf(this.Area.Items.FindByText(customer.Area));
                    }
                    this.Address.Value = customer.Address;
                    this.Decisionmaker.Value = customer.Decisionmaker;
                    this.DecisionTel.Value = customer.DecisionTel1;
                    this.DecisionTel2.Value = customer.DecisionTel2;
                    this.DecisionPosition.Value = customer.DecisionPosition;
                    DropDownListControl.DropDownListSelect(this.DecisionSex, customer.DecisionSex);
                    this.CompanyProduct.Value = customer.CompanyProduct;
                    this.Tel1.Value = customer.Tel1;
                    this.Explains.Value = customer.Explains.Trim();
                    this.AreaId.Value = customer.AreaId.ToString();
                    this.txtAreaId.Value = customer.AreaName.ToString();
                    this.TradeId.Value = customer.TradeId.ToString();
                    this.txtTradeId.Value = customer.TradeName.ToString();

                    DropDownListControl.DropDownListSelect(this.PersonId, customer.PersonId.ToString());
                    //DropDownListControl.DropDownListSelect(this.AreaId, customer.AreaId.ToString());
                    //DropDownListControl.DropDownListSelect(this.TradeId, customer.TradeId.ToString());
                    DropDownListControl.DropDownListSelect(this.ProductId, customer.ProductId.ToString());
                    DropDownListControl.DropDownListSelect(this.PropertyId, customer.PropertyId.ToString());
                }
            }
        }

        /// <summary>
        /// 添加人ID
        /// </summary>
        public string UserID
        {
            get { return this.UserId.ToString(); }
        }
        /// <summary>
        /// 页面标题
        /// </summary>
        public string PageTitle
        {
            get { return this.GetStringFromQueryString("title", ""); }
        }
        /// <summary>
        /// 标识状态
        /// </summary>
        public string Flag
        {
            get { return this.GetStringFromQueryString("flag", ""); }
        }
        public string Type
        {
            get { return this.GetStringFromQueryString("type",""); }
        }
    }
}